home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Chess++ ƒ / CChessPieces ƒ / CQueen.cp < prev    next >
Text File  |  1993-05-26  |  2KB  |  85 lines

  1. ////////////
  2. //
  3. //    CQueen.cp
  4. //
  5. //    Chess Piece methods for implementing a Queen.
  6. //
  7. //    Copyright © 1993 Steven J. Bushell. All rights reserved.
  8. //
  9. ////////////
  10.  
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. #include "CChessBoard.h"
  15. #include "CChessPiece.h"
  16. #include "CQueen.h"
  17.  
  18. extern    CIconHandle    gWhiteQueenCicnHandle;
  19. extern    CIconHandle    gBlackQueenCicnHandle;
  20.  
  21. void CQueen::IQueen(Boolean aColor)
  22. {
  23.     inherited::IChessPiece(aColor);
  24.     itsValue = 0x0800;
  25. }
  26.  
  27. void CQueen::Draw(short rank, short file)
  28. {
  29.     CIconHandle cicnHandle;
  30.     Rect aRect;
  31.     short rankQD = (rank - 1) << 5, fileQD = (file - 1) << 5;
  32.     
  33.     if (itsColor == White)
  34.         cicnHandle = gWhiteQueenCicnHandle;
  35.     else
  36.         cicnHandle = gBlackQueenCicnHandle;
  37.  
  38.     aRect.left = rankQD;
  39.     aRect.right = rankQD+32;
  40.     aRect.top = fileQD;
  41.     aRect.bottom = fileQD+32;
  42.     PlotCIcon(&aRect,cicnHandle);
  43. }
  44.  
  45. CIconHandle    CQueen::GetCicnHandle(void)
  46. {
  47.     return gWhiteQueenCicnHandle;
  48. }
  49.  
  50. Boolean    CQueen::IsValidMove(CChessBoard *aBoard, short newRank, short newFile)
  51. {
  52.     short    oldRank = aBoard->firstClickRank, oldFile = aBoard->firstClickFile;
  53.     register i,j;
  54.     short iDelta,rankDelta = newRank-oldRank,fileDelta = newFile-oldFile;
  55.     
  56.     if (abs(rankDelta) == abs(fileDelta))
  57.     {
  58.         rankDelta = abs(rankDelta)/rankDelta;
  59.         fileDelta = abs(fileDelta)/fileDelta;
  60.         for(i=oldRank+rankDelta,j=oldFile+fileDelta;i!=newRank;
  61.             i+=rankDelta,j+=fileDelta)
  62.                 if (aBoard->theBoard[i][j])
  63.                     return false;
  64.         return true;
  65.     }
  66.     
  67.     if (oldRank == newRank)
  68.     {
  69.         iDelta = abs(newFile-oldFile)/(newFile-oldFile);
  70.         for (i=oldFile+iDelta;i!=newFile;i+=iDelta)
  71.             if (aBoard->theBoard[oldRank][i])
  72.                 return false;
  73.         return true;
  74.     }
  75.     if (oldFile == newFile)
  76.     {
  77.         iDelta = abs(newRank-oldRank)/(newRank-oldRank);
  78.         for (i=oldRank+iDelta;i!=newRank;i+=iDelta)
  79.             if (aBoard->theBoard[i][oldFile])
  80.                 return false;
  81.         return true;
  82.     }
  83.     
  84.     return false;    
  85. }